const exp = require("constants");
const express = require("express");
const fs = require("fs")

const app = express()

app.use(express.static("./www"))
app.use(express.static("./"))

app.all("*",(req,res,next)=>{
    res.header('Access-Control-Allow-Origin', '*')
    res.header('Access-Control-Allow-Methods', 'get,post')
    res.header('Access-Control-Allow-Headers', 'Content-Type')
    next();
})


app.get("/getGoods_", (req,res,next)=>{

    fs.readFile("./data/goods_.json", "utf-8", (err,data)=>{
        if(err){
            res.send(JSON.stringify({
                code:0,
                msg:"数据请求失败",
                data:null
            }))
        }else{
            // console.log(data);
            res.send(JSON.stringify({
                code:1,
                msg:"数据请求成功",
                data:JSON.parse(data)
                
            }))
        }
    })

})

app.listen(3000);